Simplify case when all result expressions are identical#19732
Simplify case when all result expressions are identical#19732simonvandel wants to merge 2 commits intoapache:mainfrom
Conversation
|
CI found an error using the sqlite test suite: Makes sense that we should not remove case expressions that could cause runtime-failures (divide by zero error in this case). The question is how to detect if an expression could cause a side effect. |
I think we could mark certain operators as pure/safe/non-fallible (will never cause runtime error) and operators as division as non-pure and only optimize subtrees with only pure / non-failing expressions. |
Which issue does this PR close?
Rationale for this change
When a case expression has identical result expressions, we can remove the case, replacing it with the expression.
It's unlikely that a human would write such an expression, but a generated query may lead to such an expression.
Example where this optimization applies:
What changes are included in this PR?
Extend the expression simplifier to detect the case.
Are these changes tested?
Yes, added SLT.
The first commit shows the plan before the optimization.
Are there any user-facing changes?
Slightly better plan so fewer runtime ops